<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>考核</title>
</head>

<body>

	<script type="text/javascript">
		var arr = [1, 2, 5, 2, 1, 5, 5, 5, 8, 2, 1];
		function shuzu(arr) {
			var array = arr;
			var len = array.length;

			array.sort(function (a, b) {   //排序后更加方便去重
				return a - b;
			})

			function loop(index) {
				if (index >= 1) {
					if (array[index] === array[index - 1]) {
						array.splice(index, 1);
					}
					loop(index - 1);    //递归loop，然后数组去重
				}
			}
			loop(len - 1);
			return array;
		}
		console.log(shuzu(arr))


	</script>
	<!-- 
		1.
		if(false){
		    var a = 1;
		    let b = 2;
		}
		console.log(a);
		console.log(b); 
		答 undefined 报错

		2.
		var a = 1;
		if(true){
		    console.log(a);
		    let a = 2;
		}
		答 报错

		3.
		var a = {n: 1}
		var b = a
		a.x = a = {n: 2}
		a.x = {n:2}
		a = {n:2}
		console.log(a.n, b.n);
		console.log(a.x, b.x);
		答  2 1 undefinde {n: 2}

		4.
		console.log(c);
		var c;
		function c(a) {
		    console.log(a);
		    var a = 3;
		    function a(){
		    }
		}
		c(2);
		答: function a(){} function a(){}

		5.
		var c = 1;
		function c(c) {
		    console.log(c);
		    var c = 3;
		}
		console.log(c);
		c(2);
		答: 1 报错
		 
		6.
		var name = 'erdong';
		(function () {
			
		    if (typeof name === 'undefined') {
		        var name = 'chen';
		        console.log(name);
		    } else {
		        console.log(name);
		    }
		})();
		答:chen

		7.
		var a = 10;  
		function test() {  
		    a = 100;  
		    console.log(a);  
		    console.log(this.a);  
		    var a;  
		    console.log(a); 
		}
		test();  
		答: 100 10 100

		8.
		if (!('a' in window)) {
		    var a = 1;
		}
		console.log(a);
		答: undefined

		9.
		var a = 1;
		function c(a, b) {
		    console.log(a);
		    a = 2;
		    console.log(a);
		}
		c();
		答: un 2 

		10.
		var val=1;
		var obj={
		    val:2,
		    del:function(){
		        console.log(this);                    
		        this.val*=2;
		        console.log(val);
		    }
		}
		obj.del();
		答:  obj  1

		11.
		var name = "erdong";
		var object = {
		    name: "chen",
		    getNameFunc: function () {
		        return function () {
		            return this.name;
		        }
		    }
		}
		console.log(object.getNameFunc()());
		答: erdong

		12.
		var name = "erdong";
		var object = {
		    name: "chen",
		    getNameFunc: function () {
		        var that = this;
		        return function () {
		            return that.name;
		        }
		    }
		}
		console.log(object.getNameFunc()());
		答: chen

		13.
		(function() {
		  var a = b = 3;
		})();
		console.log(typeof a === 'undefined');
		console.log(typeof b === 'undefined');
		答: true  false
		
		14.
		console.log(typeof NaN === 'number');
		答:true

		15.
		console.log(1 + "2" + "2");
		
		console.log(1 + +"2" + "2");
		
		console.log(1 + -"1" + "2");
		
		console.log(+"1" + "1" + "2"); 
		
		console.log( "A" - "B" + "2"); 
		
		console.log( "A" - "B" + 2); 
		答：'122'  '32'  '02'   '112'  'NAN2'  NaN
		
		16.
		var a = 666;
		console.log(++a);
		console.log(a++);
		console.log(a);
		答: 667 667 668
		
		17.
		console.log(typeof a);
		function a() {}
		var a;
		console.log(typeof a);
		答:function  function

		18.
		var a;
		var b = 'undefined';
		console.log(typeof a);
		console.log(typeof b);
		console.log(typeof c);
		答:undefined string undefined
		
		19.
		var x = 1;
		if(function f(){}){
		    x += typeof f;
		}
		console.log(x);
		答: '1undefined'

		20.
		var str = "123abc";
		console.log(typeof str++);
		答: number
		
		21.
		console.log('b' + 'a' + +'a'+'a');
		答: baNaNa

		22.
		var obj = {n: 1};
		function fn2(a) {
		    a.n = 2;
		}
		fn2(obj);
		console.log(obj.n);
		答: 2
		
		23.
		var x = 10;
		function fn() {
		    console.log(x);
		}
		function show(f) {
		    var x = 20;
		    f();
		}
		show(fn);
		答: 10
		
		24.
		function foo1() {
		    return {
		        bar: "hello"
		    };
		}
		function foo2() {
		    return 
		    {
		        bar: "hello"
		    };
		}
		console.log(foo1());
		console.log(foo2());
		答: {bar: "hello"}  undefined
		
		25.
		console.log((function(){ return typeof arguments; })());
		答: 'object'
		
		26.
		console.log(0.1 + 0.2 == 0.3);
		答: false
		 -->
</body>

</html>